package ua.com.fesvlast.hotel.model.utils;

import ua.com.fesvlast.hotel.model.enteties.Contacts;
import ua.com.fesvlast.hotel.model.enteties.Users;

public class Validator {
	private static String message;
	
	public static boolean validateUser(Users user){
		
		if(user.getLogin().equals("") || user.getLogin()==null){
			message="The login is empty!";
			return false;
		}
		
		if(user.getLogin().length()<3){
			message="Login must be more than 3 symbols";
			return false;
		}
		if(user.getPassword().equals("") || user.getPassword()==null){
			message="The password is empty!";
			return false;
		}
		if(user.getPassword().length()<6){
			message="Password must be at least 6 symbols";
			return false;
		}
		else if(user.getPassword().matches("\\w*\\s+\\w*")){
			message="Password cannot contain space.";
			return false;
		}
		
		return true;
	}
	
	public static boolean validateContact(Contacts contact){
		if(contact.getFirstName()==null || contact.getFirstName()==""){
			message="First name is empty";
			return false;
		}
		if(contact.getLastName()==null || contact.getLastName()==""){
			message="Last name is empty";
			return false;
		}
		
		if(!contact.getEmail().matches("\\w+@\\w+\\.\\w+")){
			message="Invalid email address!";
			return false;
		}
		
		return true;
	}
	
	public static boolean validateEmail(String email){
		if(email==null || email.equals("")){
			message="Empty email address!";
			return false;
		}
		if(!email.matches("\\w+@\\w+\\.\\w+")){
			message="Invalid email address!";
			return false;
		}
		
		if(email.length()<6){
			message="Invalid email address!";
			return false;
		}
		
		return true;	
	}
	public static String getMessage(){
		return message;
	}

}
